<?php
require("include/top.php");

if((isset($_POST['valid']))||(isset($_POST['modify']))) {require(FORM_PATH."edit_fotos.form.php");}




if (isset($_GET['id'])){
	$pdt=new Product($_GET['id']);
	
		if (($pdt) && ($_SESSION['vendor']['id']==$pdt['vendor']['id'])) {
			$fotos=$pdt->getPhotos();
			$tpl->assign('fotos',$fotos);
			
			$foto_id=$pdt['photo_id'];
			if ($foto_id>0) {
			$foto_principal=new PhotoProduct($foto_id);
			}
			else {$foto_principal=new PhotoProduct();}
			$tpl->assign('foto_principal',$foto_principal);
			$tpl->assign('pdt',$pdt);
		
			$_SESSION['Product']=$pdt;
			$_SESSION['Product']->load;
			$_SESSION['foto_principal']=new PhotoProduct();
			$_SESSION['newPhoto0']=new PhotoProduct();
			$_SESSION['newPhoto1']=new PhotoProduct();
			$_SESSION['newPhoto2']=new PhotoProduct();
			$_SESSION['newPhoto3']=new PhotoProduct();
			$_SESSION['newPhoto4']=new PhotoProduct();
			
		}

}
if((isset($_GET['recap']))&&(isset($_POST['valid_fotos']))&&($_GET['id'])) {

header('Location:edit_product.php?id='.$pdt['id'].'&recap=1');

}
elseif ((!isset($_GET['recap']))&&(isset($_POST['valid_fotos']))&&($_GET['id'])) {

header('Location:listing_products.php');
}
elseif(isset($_GET['id'])) {



	$tpl->display("header.tpl");
    $tpl->display("menu.tpl");
	$tpl->display("edit_fotos.tpl");
	$tpl->display("footer.tpl");
	
}
	
else {header('Location:login.php');}
	
require("include/bottom.php");	

?>
